import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';

// Text(
// '选择或搜索目的地小站',
// style: TextStyle(
// fontSize: 14,
// color: Colors.black.withOpacity(0.4),
// ),
// )

class WayStationSearchBar extends StatelessWidget {
  final TextEditingController? controller;
  final FocusNode? textfocus;
  final GestureTapCallback? tapCallback;
  final bool enableInput;
  final void Function(String)? searchCallback;

  WayStationSearchBar(
      {this.controller,
      this.tapCallback,
      this.enableInput = false,
      this.searchCallback,
      this.textfocus});

  @override
  Widget build(BuildContext context) {
    var noneBorder = OutlineInputBorder(
      borderSide: BorderSide.none,
      gapPadding: 0,
    );
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.only(left: 10),
      height: 40,
      decoration: BoxDecoration(
        color: const Color(0xFFF8F8F8),
        borderRadius: BorderRadius.circular(8),
      ),
      child: Container(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset(
              "assets/icons/icon_search_black.png",
              width: 15,
              height: 15,
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(left: 1),
                child: GestureDetector(
                  child: TextField(
                    enableInteractiveSelection: true,
                    focusNode: textfocus,
                    enabled: enableInput,
                    inputFormatters: [
                      FilteringTextInputFormatter.deny(appContext.emojiRegexp)
                    ],
                    textAlignVertical: TextAlignVertical.bottom,
                    controller: controller,
                    cursorColor: ThemeColor.primaryColor,
                    textInputAction: TextInputAction.search,
                    onSubmitted: (value) {
                      if (this.searchCallback != null) {
                        this.searchCallback!(value);
                      }
                    },
                    decoration: InputDecoration(
                        hintText: S.of(context).Select_or_search_sites,
                        hintStyle: TextStyle(
                          fontSize: 14,
                          color: Colors.black.withOpacity(0.4),
                        ),
                        fillColor: const Color(0xFFF8F8F8),
                        filled: true,
                        enabledBorder: noneBorder,
                        focusedBorder: noneBorder),
                  ),
                  onTap: ClickUtils.debounce(() => tapCallback),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
